package org.example.genweb.controller;

import org.example.genweb.dto.TableInfo;
import org.example.genweb.entity.DatabaseConfig;
import org.example.genweb.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author :Mr.zhou
 * @description: TODO edit class Description
 * @create date: 2025/4/8 17:49
 */
@RestController
@RequestMapping("/users")
@Tag(name = "用户controller")
public class DBController {
    @Autowired
    private DatabaseService databaseService;
    @Operation(summary = "配置数据库链接")
    @PostMapping("/databases/config")
    public void configDatabase(@RequestBody DatabaseConfig config) {
        databaseService.configDatabase(config);
    }

    @Operation(summary = "测试数据库链接")
    @PostMapping("/databases/test")
    public boolean testDatabase(@RequestBody DatabaseConfig config) {
        return databaseService.testDatabase(config);
    }

    @Operation(summary = "获取表结构信息")
    @PostMapping("/databases/tables")
    public List<TableInfo> getTableInfo(@RequestBody DatabaseConfig config) {
        return databaseService.getTableInfo(config);
    }
}
